<template>
  <div>
    <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="账号" prop="user">
        <el-input type="text" v-model="ruleForm.user" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="pass">
        <el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
      </el-form-item>

      <el-row>
        <el-col :span=15>
          <el-form-item label="验证码" prop="vc">
            <el-input v-model.number="ruleForm.vc"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item>
        <el-row>
          <el-col :span=12>
            <el-button @click="submitForm()" round>提交</el-button>
          </el-col>
          <el-col :span=12>
            <el-button @click="resetForm()" round>重置</el-button>
          </el-col>
        </el-row>


      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "Login",
  data() {
    var checkVc = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入验证码'));
      } else {
        callback();
      }

    };
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'));
      } else {
        callback();
      }
    };
    var validateUser = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入账号'));
      }  else {
        callback();
      }
    };
    return {
      ruleForm: {
        user: '',
        pass: '',
        vc: ''
      },
      rules: {
        user: [
          { validator: validateUser, trigger: 'blur' }
        ],
        pass: [
          { validator: validatePass, trigger: 'blur' }
        ],
        vc: [
          { validator: checkVc, trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    resetForm(){
      this.ruleForm.user = '',
          this.ruleForm.pass = '',
          this.ruleForm.vc = ''
    },
    submitForm(){
      alert("表单提交中....")
    }
  }
}
</script>

<style scoped>
.demo-ruleForm {
  position: relative;
  left: -18px;
}
</style>